<!DOCTYPE html>

<html>

<head>
    <title>ast-editor</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="/static/icon/icon.svg" rel="icon" type="image/x-icon">
    <style>
        body {
            margin: 0px;
            padding: 0px;
        }
        
        .main {
            position: absolute;
            top: 0px;
            bottom: 0px;
            left: 0px;
            right: 5px;
        }
        
        .flex {
            display: flex;
            flex-direction: column;
            height: 100%;
            width: 100%;
        }
        
        .header {
            text-align: center;
            font-size: 1.5rem;
            margin-top: 10px;
            font-weight: bolder;
        }
        
        .inline {
            display: inline-block;
        }
        
        .editor-block {
            width: 98%;
        }
        
        .editor-header {
            text-align: center;
            margin: 10px;
            font-size: 1.1rem;
        }
        
        .editor {
            width: 100%;
            height: 100%;
            border: 1px solid grey;
        }
        
        .tool {
            text-align: right;
            margin: 10px;
            margin-right: 20px;
            height: 25px;
        }
        
        .result {
            border: 1px;
            border-style: solid;
            height: 149px;
        }
    </style>
    <script src="https://7072-prd-ffx26-1255301037.tcb.qcloud.la/321zou.com/dsl/jquery/jquery-3.5.1.min.js?v=238619"></script>
    <script src="https://7072-prd-ffx26-1255301037.tcb.qcloud.la/321zou.com/dsl/monaco-editor/min/vs/loader.js"></script>
</head>

<body>

    <div class="main">
        <div class="flex">
            <div class="editor-header"><span>语法树(AST)</span></div>
            <div id="astContent" class="editor inline"></div>
        </div>
    </div>

    <script>
        require.config({
            paths: {
                vs: 'https://7072-prd-ffx26-1255301037.tcb.qcloud.la/321zou.com/dsl/monaco-editor/min/vs'
            }
        });
        var astEditor = null;
        require(['vs/editor/editor.main'], function() {

            var astJson = {};

            astEditor = monaco.editor.create(document.getElementById('astContent'), {
                value: JSON.stringify(astJson, "", 4),
                language: 'json',
                scrollBeyondLastLine: false,
            });
        });

        //action注册机制：执行action
        function callAction(action, param) {
            if ("showHelp" === action) {
                astEditor.setValue(JSON.stringify(helpJSON));
            } else if ("setEditorValue" === action) {
                astEditor.setValue(JSON.stringify(param));
            }
            setTimeout(() => {
                astEditor.getAction('editor.action.formatDocument').run();
            }, 10);
        }
        //action注册机制：注册action调用
        window.parent.registerCallAction(callAction);
    </script>
</body>

</html>